home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Mathematics / TeX / TeXsis-2.15 / TXSenvmt.tex < prev    next >
Encoding:
Text File  |  1992-08-04  |  30.0 KB  |  676 lines

  1. %% TXSenvmt.tex                                 TeXsis version 2.15
  2. %  $Revision: 15.10 $  :  $Date: 92/07/31 15:42:00 $  :  $Author: myers $
  3. %=======================================================================*
  4. % SPECIAL TEXT ENVIRONMENTS      -  This file is a part of TeXsis
  5. %                       (C) copyright 1991 by Eric Myers and Frank Paige.
  6. %
  7. %
  8. %       These macros provide a variety of simple enviroments for arranging
  9. %   text in special ways. They are listed here and described in more
  10. %   detail below. Generally the syntax is \NAME... \endNAME.
  11. %
  12. %  The following "flush environments" arrange text in special ways:
  13. %
  14. %       \center         Center each line.
  15. %       \flushleft      Make each line flush left.
  16. %       \flushright     Make each line flush right.
  17. %       \raggedcenter   Make each line as long as possible and then
  18. %                       center it.
  19. %
  20. %  Use these in vertical mode.  For the horizontal mode equivalants
  21. %  are: \hcenter, \hflushleft, \hflushright 
  22. %
  23. %   The following are for making various sorts of lists:
  24. %
  25. %       \itemize        List of items, with a bullet in front of each.
  26. %                       Use \itm to begin each item.
  27. %       \enumerate      Makes a list of items, each of them numbered.
  28. %                       Use \itm to begin each item.
  29. %       \description    List of items and descriptions, with the form:
  30. %                         item1   text for item1, which may take
  31. %                                 more than one line
  32. %                         item2   text for item2
  33. %                               ...
  34. %                       Use \itm{item1}, etc... (see below).
  35. %
  36. %       The following display theorems and proofs in quasi-SIAM format
  37. % with automatic numbering:
  38. %
  39. %       \theorem
  40. %       \lemma
  41. %       \definition
  42. %       \proof
  43. %
  44. %       The following are designed for typing computer code, TeX examples ,
  45. %  and similar material:
  46. %
  47. %       \Listing        Prints text in \tt type, with \obeylines,
  48. %                       \obeyspaces, as appropriate for computer code
  49. %                       listings.
  50. %       \ListCodeFile{filename} to list source code from a file.
  51. %       \TeXquoteon     Makes | a TeX quote: everything in | ... | is
  52. %                       printed verbatim in \tt type.
  53. %       \TeXexample     Prints a TeX example verbatim in \tt type, with |
  54. %                       being the escape character and |endTeXexample
  55. %                       ending the enviroment. Can be used for examples
  56. %                       continuing over more than one page.
  57. %       \ttverbatim     Makes all characters ordinary and begins a group
  58. %                       using \tt type.
  59. %       \begintt        Example macro taken from The TeXbook.
  60. %       \beginlines     Example macro taken from The TeXbook.
  61. %
  62. %
  63. % Source: adapted from TechRpt's TechEnv and the TeXbook
  64. %
  65. % Dependencies: TXSmacs.tex
  66. %======================================================================*
  67. \message{Environments.}
  68. \catcode`@=11                                   % make @ a letter for now
  69. \chardef\other=12
  70.      
  71. %==================================================*
  72. % CENTERING ENVIRONMENTS: 
  73. %       \center, \flushleft, \flushright, \raggedcenter
  74. % Note: these are all \obeylines environments
  75.      
  76. \def\center{% begin centering environment
  77.    \flushenv                            % general setup
  78.    \advance\leftskip \z@ plus 1fil      % add hfil glue on each
  79.    \advance\rightskip \z@ plus 1fil     % side
  80.    \obeylines\@eatpar}                  % obey line ends
  81.      
  82. \def\flushright{% begin flush right environment
  83.     \flushenv                           % general setup
  84.     \advance\leftskip \z@ plus 1fil     % hfil on left
  85.     \obeylines\@eatpar}                 % obey line ends
  86.      
  87. \def\flushleft{% begin flush left environment
  88.    \flushenv                            % general setup
  89.    \advance\rightskip \z@ plus 1fil     % hfil on right
  90.    \obeylines\@eatpar}                  % obey line ends
  91.      
  92.  
  93. \def\flushenv{%  common startup for all flush/center environments
  94.     \vskip \z@                          % force vertical mode
  95.     \bgroup                             % begin grouping
  96.      \def\flushhmode{F}%                % flag: not hmode
  97.      \parindent=\z@  \parfillskip=\z@}  %
  98.      
  99. \def\endcenter{\endflushenv}
  100. \def\endflushleft{\endflushenv}
  101. \def\endflushright{\endflushenv}
  102.  
  103. % \@eatpar gets rid of any \par that follows
  104.      
  105. \def\@eatpar#1{\ifx#1\par\relax\else#1\fi}
  106.      
  107. %---------------------------------*
  108. %    \raggedcenter centers ragged lines, e.g. for titles.  Each line will
  109. % be as long as possible, centered. Line breaks in the manuscript file are
  110. % ignored.
  111.  
  112.  
  113. \def\raggedcenter{%     center lines as long as they can be
  114.     \flushenv                           % do common stuff
  115.     \advance\leftskip\z@ plus4em        % add stretch to sides
  116.     \advance\rightskip\z@ plus 4em      % add stretch to sides
  117.     \spaceskip=.3333em \xspaceskip=.5em %
  118.     \pretolerance=9999 \tolerance=9999  %
  119.     \hyphenpenalty=9999 \exhyphenpenalty=9999   % no hyphens!
  120.     \@eatpar}                           %
  121.  
  122. \def\endraggedcenter{\endflushenv}              % ends like all flushenv's
  123.  
  124. %---------------------------------*
  125. %    \hcenter, \hflushleft, \hflushright are like the things above,
  126. % but are for use in horizontal mode. They put the results in a box of
  127. % size zero.  This is no longer automatic in \center and its variations,
  128. % to avoid confusion.
  129. % Notes: \vtop makes the TOPS of the items line up; \vbox would make the
  130. % bottoms (actually, the baselines) line up.
  131.  
  132.      
  133. \def\hcenter{\hflushenv                         %
  134.    \advance\leftskip \z@ plus 1fil              %
  135.    \advance\rightskip \z@ plus 1fil             %
  136.    \obeylines\@eatpar}                          %
  137.  
  138. \def\hflushright{\hflushenv                     %
  139.     \advance\leftskip \z@ plus 1fil             %
  140.     \obeylines\@eatpar}                         %
  141.      
  142. \def\hflushleft{\hflushenv                      %
  143.     \advance\rightskip \z@ plus 1fil            %
  144.     \obeylines\@eatpar}                         %
  145.      
  146. \def\hflushenv{% common startup for all hflush/hcenter environments:
  147.    \def\par{\endgraf\indent}%                   % for use in hmode
  148.    \hbox to \z@ \bgroup\hss\vtop                % start a box of size zero
  149.    \flushenv\def\flushhmode{T}}                 %
  150.  
  151. \def\endflushenv{% common end to all flush/center environments
  152.    \ifhmode\endgraf\fi                          % if hmode, end \par
  153.    \if T\flushhmode \egroup\hss\fi              % close group and box, or
  154.    \egroup}                                     % end the grouping
  155.      
  156. \def\endhcenter{\endflushenv}
  157. \def\endhflushleft{\endflushenv}
  158. \def\endhflushright{\endflushenv}
  159.      
  160. %==================================================*
  161. % LIST ENVIRONMENTS:
  162. %
  163. %       All 'list' environments are surrounded by a certain amount of skip.
  164. % These skips are: \EnvTopskip, \EnvBottomskip, \EnvLeftskip, \EnvRightskip
  165. % These are set here, but you may change them if you like.
  166.      
  167. \newskip\EnvTopskip     \EnvTopskip=\medskipamount    % skip before
  168. \newskip\EnvBottomskip  \EnvBottomskip=\medskipamount    % skip after
  169. \newskip\EnvLeftskip    \EnvLeftskip=2\parindent    % left indent
  170. \newskip\EnvRightskip   \EnvRightskip=\parindent    % right margin in too
  171. \newskip\EnvDelt@skip   \EnvDelt@skip=0pt        % nested skip amount
  172. \newcount\@envDepth     \@envDepth=\z@              % depth of environments
  173.  
  174.  
  175. %       \beginEnv{<name>} does common processing for starting a 
  176. % list environment. \endEnv{<name>} does common end procesing, 
  177. % and checks the name to make sure that the environments balance.
  178.  
  179. \def\beginEnv#1{%  begin a ``list'' environment
  180.    \begingroup                          % environment is inside a group
  181.    \def\@envname{#1}%                   % save envmt name, to check at end
  182.    \ifvmode\def\@isVmode{T}%            % remember existing V/H mode
  183.    \else\def\@isVmode{F}\vskip 0pt\fi   % hmode: force vertical mode
  184. %
  185.    \ifnum\@envDepth=\@ne\parindent=\z@\fi % 1st envmt?  no parindent
  186.    \global\advance\@envDepth by \@ne    % increment level by one
  187.    \EnvDelt@skip=\baselineskip          % \EnvDelt@skip is \baselineskip
  188.    \advance\EnvDelt@skip by-\normalbaselineskip%  minus \normalbaselineskip
  189.    \@setenvmargins\EnvLeftskip\EnvRightskip % now adjust margins.
  190.    \setenvskip{\EnvTopskip}%            % get appropriate topskip
  191.    \vskip\skip@\penalty-500             % and do it (good place to break)
  192.    }
  193.      
  194.  
  195. \def\endEnv#1{%     end a ``list'' environment
  196.    \ifnum\@envDepth<1                   % is there nothing open?
  197.       \emsg{> Tried to close ``#1'' environment, but no environment open!}%
  198.       \begingroup                       % \endgroup below would produce error
  199.    \else                                % No: there was an environment open
  200.       \def\test{#1}%                    % was right thing closed?
  201.       \ifx\test\@envname\else           % check that the names match
  202.          \emsg{> Miss-matched environments!}%
  203.          \emsg{> Should be closing ``\@envname'' instead of ``\test''}%
  204.       \fi                               %
  205.    \fi                                  %
  206. %
  207.    \vskip 0pt                           % force vmode, finish any paragraph
  208.    \setenvskip\EnvBottomskip            % and skip a bottomskip which is
  209.    \vskip\skip@\penalty-500             %    appropriate here (good breakpoint)
  210.    \xdef\@envtemp{\@isVmode}%           % save \@isVmode for outside group
  211.    \endgroup                            % end grouping of environment
  212.    \global\advance\@envDepth by -\@ne   % decrement environment level
  213.    \if F\@envtemp\vskip-\parskip\noindent\fi % no indent if didn't start in vmode
  214.    }
  215.      
  216.  
  217. %       \setenvskip chooses a skip amount based on the current \@envDepth,
  218. % and puts it into \skip@, which is a temporary skip register.
  219.      
  220. \def\setenvskip#1{\skip@=#1 \divide\skip@ by \@envDepth}
  221.      
  222.  
  223. %       \@setenvmargins{<left amount>}{<right amount>} adjusts the area of
  224. %  the page to be used by changing \rightskip, \leftskip, and the display
  225. % sizes.  Values given should be skips.
  226.      
  227. \def\@setenvmargins#1#2{%     set left and right margins
  228.    \advance \leftskip  by #1    \advance \displaywidth by -#1   %
  229.    \advance \rightskip by #2    \advance \displaywidth by -#2   %
  230.    \advance \displayindent by #1}                               %
  231.      
  232.  
  233. %------------------------------*
  234. % \itemize
  235. %
  236. %       \itemize puts a bullet (or whatever you define as \itemmark)
  237. % in front of each item.  Use \itm to begin a new item.
  238.      
  239. \def\itemize{\beginEnv{itemize}% itemized list of things
  240.    \let\itm=\itemizeitem                % define \itm 
  241.    \if F\@isVmode\vskip-\parskip\fi     % if h-mode kill skip from first \itm
  242.    }
  243.  
  244. \def\itemizeitem{%      \itm for \itemize
  245.    \par\noindent                                % start new paragraph
  246.    \hbox to 0pt{\hss\itemmark\space}}%          % put marker to left
  247.      
  248. \def\enditemize{\endEnv{itemize}}%              % terminate
  249.      
  250. \def\itemmark{$\bullet$}                        % default marker for \itemize
  251.  
  252. %------------------------------*
  253. % \enumerate
  254. %       \enumerate makes a list of items, each of them numbered.  You can
  255. % nest \enumerate within \enumerate.  Begin each item with \itm.
  256. % Note the extensive use of local registers (only one \enumcnt is allocated;
  257. % TeX takes care of which one is currently needed.  \enumlead stores the
  258. % rest of the values only to print out item labels.) Note that \label
  259. % can be used to get the current value of an item label. 
  260. % Usage:
  261. %       \enumerate              % to start a list
  262. %       \itm  <text>            % for each numbered paragraph
  263. %           ...
  264. %       \endenumerate           % at end the list
  265. %
  266.  
  267. \newcount\enumDepth     \enumDepth=\z@
  268. \newcount\enumcnt
  269.      
  270. \def\enumerate{\beginEnv{enumerate}%
  271.    \global\advance\enumDepth by \@ne            % start another level of nesting
  272.    \setenumlead                                 % set the leader
  273.    \enumcnt=\z@                                 % reset counter to zero
  274.    \let\itm=\enumerateitem                      % define \itm
  275.    \if F\@isVmode\vskip-\parskip\fi     % if h-mode kill skip from first \itm
  276.    }
  277.  
  278. \def\enumerateitem{% \itm for \enumerate
  279.     \par\noindent                 
  280.     \advance\enumcnt by \@ne                    %
  281.     \edef\lab@l{\enumlead \enumcur}%            % for using \label
  282.     \hbox to \z@{\hss \lab@l \enummark          % number and punctuation
  283.        \hskip .5em}%                            % and a skip
  284.     \ignorespaces}                              %
  285.      
  286. \def\endenumerate{%                             %
  287.    \global\advance\enumDepth by -\@ne           % pop out one level
  288.    \endEnv{enumerate}}%                         % end the environment
  289.  
  290. %----------*
  291. % DIFFERENT STYLES OF EUMARATION: \enumpoints, \enumoutline,
  292. % \enumNumOutline, etc...  Design your own!
  293. %
  294. % The basic idea:  When \itm is invoked the item label is constructed
  295. % as  ``\enumlead\enumcur\enummark''  where \enumlead is the leading 
  296. % part of the label (which will be the same for all item in this level 
  297. % of the list), \enumcur is the appropriately formated value of \enumcnt, 
  298. % the item counter, and \enummark is the trailing punctuation (usually
  299. % a period, but could be a parenthesis).
  300. %
  301. % To define an enumeration style you must define \setnumlead, which
  302. % will in turn define \enumlead  when a list is begun by \enumerate.
  303. % You must also define \enumcur to put out the appropriate item label.  
  304. % Since lists can be contained within lists we use \enumDepth to keep track of
  305. % how deep we are in a sub-list.
  306. %
  307. % The styles \enumpoints, \enumoutline and \enumNumOutline should be 
  308. % considered as useful examples.  Be sure to call them BEFORE you say 
  309. % \enumerate.
  310.  
  311.  
  312. %       \enumpoints just numbers the items like so: "ii.jj.kk...."
  313. % Note the use of \edef in \setnumlead to get the CURRENT value
  314. % of \enumcur, whereas the value in the definition of \enumcur
  315. % is the value used later, when \itm is used.
  316.      
  317. \def\enumPoints{%  enumerate by numerical points
  318.    \def\setenumlead{\ifnum\enumDepth>1          % a list inside a list?
  319.           \edef\enumlead{\enumlead\enumcur.}%   % yes: lead is previous label
  320.       \else\def\enumlead{}\fi}%                 % no: just number at first
  321.    \def\enumcur{\number\enumcnt}%               %
  322.    }
  323. \def\enumpoints{\enumPoints}                    % backward compatability (2.13)
  324.  
  325.  
  326. %       \enumOutline lists the items in an outline form, using 
  327. % upper case roman numerals, upper case letters, lower case roman
  328. % numerals, lower case letters, arabic numbers, and finally bullets.
  329. % Note the use of \ifcase\enumDepth, and the macros \letterN and
  330. % \LetterN defined below.
  331.     
  332. \def\enumOutline{% enumerate a list in outline form, Roman Caps. first
  333.    \def\setenumlead{\def\enumlead{}}%           % no leading part of label
  334.    \def\enumcur{\ifcase\enumDepth               % For given level choose...
  335.      \or\uppercase{\XA\romannumeral\number\enumcnt}% 1)  UC Roman numeral
  336.      \or\LetterN{\the\enumcnt}%                 % 2) UC letter
  337.      \or\XA\romannumeral\number\enumcnt         % 3) LC Roman numeral
  338.      \or\letterN{\the\enumcnt}%                 % 4) LC letter
  339.      \or{\the\enumcnt}%                         % 5) arabic number
  340.      \else $\bullet$\space\fi}%                 % or a bullet
  341.    }
  342. \def\enumoutline{\enumOutline}                  % backward compatability (2.13)
  343.  
  344.  
  345. %       \enumNumOutline sets up an outline starting from arabic 
  346. % numbers numbers rather than Roman caps.
  347.      
  348. \def\enumNumOutline{%  enumerate a list in outline form, numbers first
  349.    \def\setenumlead{\def\enumlead{}}%           % no leading part of a label.
  350.    \def\enumcur{\ifcase\enumDepth               % for a given level choose...
  351.       \or{\XA\number\enumcnt}%                  % 1) arabic number
  352.       \or\letterN{\the\enumcnt}%                % 2) LC letter
  353.       \or{\XA\romannumeral\number\enumcnt}%     % 3) LC roman numeral
  354.       \else $\bullet$\space\fi}%                % or a bullet
  355.    }
  356. \def\enumnumoutline{\enumNumOutline}            % backward compatability (2.13)
  357.  
  358.      
  359. % \LetterN{n} gives the nth letter in the uppercase alphabet
  360. % \letterN{n} gives the nth letter in the lowercase alphabet
  361.      
  362. \def\LetterN#1{\count@=#1 \advance\count@ 64 \XA\char\count@}
  363. \def\letterN#1{\count@=#1 \advance\count@ 96 \XA\char\count@}
  364.      
  365.  
  366. % TeXsis Defaults:
  367.  
  368. \def\enummark{.}                                % default punctuation
  369. \def\enumlead{}                                 % start with nothing in label
  370. \enumpoints                                     % default style
  371.      
  372. %------------------------------*
  373. % \description gives a list of items labeled by text, not numbers.
  374. %
  375. %       foo1    text, which may take
  376. %               more than one line
  377. %       foo2    more text
  378. %
  379. % Usage:
  380. %
  381. %       \description{amount to indent as \hbox contents}
  382. %       \itm{<name1>} text1
  383. %       \itm{<name2>} text2
  384. %       ...
  385. %       \enddescription
  386. % where <name...> is the text to label the item.  <name> may take more than
  387. % one line.
  388. %       Typically, the argument to \description is the longest single line
  389. % <name>.  You can also use \hskip if you want a particular distance.
  390. % NOTE that \parindent may be 0 inside an environment, so \hskip\parindent
  391. % probably won't do what you want.
  392. %
  393. % If the label text comes out wider than the indent space allowed 
  394. % the text will be broken into several lines.  Saying \singlelinetrue 
  395. % will instead put the label text on a line by itself above the 
  396. % item. \singlelinefalse is the default.
  397.      
  398. \newbox\@desbox                 % used to determine how far to shift text
  399. \newbox\@desline                % box for description line(s)
  400. \newdimen\@glodeswd             % used to get \wd\@desbox inside a group
  401. \newcount\@deslines             % used to count number of lines in description
  402. \newif\ifsingleline \singlelinefalse            % default is to break long labels
  403.      
  404.  
  405. \def\description#1{\beginEnv{description}% ``description'' list environment
  406.    \setbox\@desbox=\hbox{#1}%                   % get template in a box
  407.    \@glodeswd=\wd\@desbox                       % get width of that box
  408.    \@setenvmargins{\@glodeswd}{0pt}%            % indent left margin
  409.    \let\itm=\descriptionitem                    % define \itm
  410.    \if F\@isVmode\vskip-\parskip\fi     % if h-mode kill \parskip from \itm
  411.   }%                                           % end of \description
  412.  
  413.  
  414. \def\descriptionitem#1{% definition of \itm for \description
  415.    \goodbreak\noindent                          % end old item, start next
  416.    \setbox\@desline=\vtop\bgroup                % get label text in a box
  417.       \hfuzz=100cm\hsize=\@glodeswd             % suppress overfull box msg
  418.       \rightskip=\z@ \leftskip=\z@              % no margins in this box
  419.       \raggedright                              % ragged right margin in box
  420.       \noindent{#1}\par                         % text of the label
  421.       \global\@deslines=\prevgraf               % get line count
  422.       \egroup                                   % end of \setbox
  423. %
  424.    \ifsingleline                                % long labels on their own line?
  425.      \ifnum\@deslines>1                         % Yes: are there several lines?
  426.         \@deslineitm{#1}%                       % Yes: put them on one line
  427.      \else                                      % one line might ll be too long
  428.         \setbox\@desline=\hbox{#1}%             % re-set in a box to get width
  429.         \ifdim \wd\@desline>\wd\@desbox         % is it too wide?
  430.             \@deslineitm{#1}%                   % Yes: set it on lone line
  431.         \else\@desitm\fi                        % else dump the label
  432.      \fi                                        %
  433.    \else                                        % else \singlelinefalse
  434.      \@desitm                                   % ...so just dump the label
  435.    \fi                                          % end \ifsingleline
  436.    \ignorespaces}
  437.  
  438. \def\@desitm{% print \description item
  439.    \noindent
  440.    \hbox to \z@{\hskip-\@glodeswd               % go back for indent
  441.      \hbox to \@glodeswd{\vtop to \z@{\box\@desline\vss}% unbox it
  442.      \hss}\hss}}                                % some glue for a fit
  443.  
  444. \def\@deslineitm#1{% \description item on a separate line
  445.    \hbox{\hskip-\@glodeswd {#1}\hss}%           % Yes: label all on one line
  446.    \vskip-\parskip\nobreak\noindent             %   then begin entry on next line
  447.    }
  448.  
  449. \def\enddescription{\ifhmode\par\fi             % finish any existing \itm
  450.    \@setenvmargins{-\wd\@desbox}{0pt}%          % doing \@setenvmargins
  451.    \endEnv{description}}
  452.      
  453. %------------------------------*
  454. %   \example is a simple way to just indent some text.  It's like
  455. % the ``list'' environments but all it does is indent on the left
  456. % and the right and go to singlespacing.
  457.  
  458.  
  459. \def\example{\beginEnv{example}% 
  460.    \vskip\EnvDelt@skip                          % do extra skip above
  461.    \parskip=\z@ \parindent=\z@                  % set \par indentation to zero
  462.    \baselineskip=\normalbaselineskip            % singlespaced
  463.    }                                            %
  464.  
  465. \def\endexample{\endEnv{example}%               % end environment
  466.    \noindent}%                                  % undo par
  467.  
  468. %------------------------------*
  469. %   \Listing is an environment for computer code listings.  It's
  470. % set in \tt type, with \obeylines and \obeyspaces and no justification.
  471. % { and } are just characters, so to get grouping use \bgroup ... \egroup
  472. % Indentation is controled as in the ``list'' environments.
  473.  
  474.  
  475. \def\Listing{\beginEnv{Listing}%                %
  476.    \vskip\EnvDelt@skip                          % do extra skip
  477.    \baselineskip=\normalbaselineskip            % singlespaced
  478.    \obeylines                                   % respect line endings
  479.    \parskip=\z@ \parindent=\z@                  % set \par indentation to zero
  480.    \obeyspaces\tt                               % and obey spaces too
  481.    \def\\##1{\char92##1}%                       % \ for macro names
  482.    \catcode`\{=\other \catcode`\}=\other        % { and } just characters
  483.    \catcode`\(=\other \catcode`\)=\other        % ( and ) just characters
  484.    \catcode`\"=\other \catcode`\|=\other        % " and | just characters
  485.    \catcode`\%=\other \catcode`\&=\other        % so %  and & are characters
  486.    \catcode`\-=\other \catcode`\==\other        % so -  and = are characters
  487.    \catcode`\$=\other \catcode`\#=\other        % so $  and # are characters
  488.    \catcode`\_=\other \catcode`\^=\other        % so _  and ^ are characters
  489.    }                                            %
  490.  
  491. \def\endListing{\endEnv{Listing}}     % end \Listing
  492.  
  493.  
  494. % Use \ListCodeFile{<filename>} to directly include a source file
  495. % in the document.  Use this INSTEAD of \Listing, not after it.
  496. % Nothing in this file is ``active,'' so you cannot have TeX commands
  497. % in the file.  Example:  \ListCodeFile{hello.c}
  498.  
  499. \def\ListCodeFile#1{\Listing            % invoke \Listing and read in file
  500.    \hsize=2\hsize\raggedright           % allow overflow in right margin
  501.    \Listingtabs                         % ^^I <tab> fakes tabs
  502.    \catcode`\\=\other                   % \ is not active!
  503.    \input #1\relax                      % read in source file
  504.    \endListing}
  505.  
  506.  
  507. {\catcode`\^^I=\active % these lines must end with %
  508.   \gdef\Listingtabs{\catcode`\^^I\active \let^^I=\@listingtab}
  509. }
  510.  
  511. \def\@listingtab{\phantom{XXXXXXXX}}            % 1 tab = 8 spaces 
  512.                                                 % (could be improved some day...)
  513.  
  514. %------------------------------*
  515. %        \TeXexample is an environment for TeX examples. The only special
  516. % characters are <space>, which does the usual thing, and "|", which is the
  517. % escape character. To use a macro in this environment, begin the name with
  518. % "|" instead of "\". In particular, |char`|| gives a |. The enviroment is
  519. % ended with |endTeXexample, NOT \endTeXexample:
  520. %
  521. %       \TeXexample
  522. %           <TeX stuff>
  523. %       |endTeXexample
  524. %
  525. %  <TeX stuff> is printed in \tt type indented by \EnvLeftskip using
  526. %  \obeylines and \obeyspaces and single spaced.  If necessary, it will
  527. %  be split across pages.
  528.      
  529. \def\TeXexample{\beginEnv{TeXexample}%  % TeX examples
  530.    \vskip\EnvDelt@skip                  % add some extra skip above
  531.    \parskip=\z@ \parindent=\z@          % set \par indentation to zero
  532.    \baselineskip=\normalbaselineskip    % singlespaced
  533.    \def\par{\leavevmode\endgraf}%       % \par also gives \leavevmode
  534.    \obeylines                           % respect line endings
  535.    \catcode`|=\z@                       % make | the escape character
  536.    \ttverbatim                          % begin \tt type in a group
  537.    \@eatpar}%                           % eat initial \par
  538.  
  539. \def\endTeXexample{%                    % end \TeXexample
  540.    \vskip 0pt                           % 
  541.    \endgroup                            % end \ttverbatim
  542.    \endEnv{TeXexample}}                 % end the environment
  543.      
  544. %------------------------------*
  545. %       \ttverbatim makes everything except "|" into \other, then switches
  546. % into \tt type. "|" is made active by \TeXquoteon and is made the escape
  547. % character by \TeXexample and \begintt.
  548.      
  549. \def\ttverbatim{\begingroup                     % begin a group
  550.    \catcode`\(=\other \catcode`\)=\other        % make everything "other"
  551.    \catcode`\"=\other \catcode`\[=\other        %
  552.    \catcode`\]=\other                           %
  553.    \let\do=\uncatcode \dospecials               %
  554.    \obeyspaces \obeylines                       % obey line ends and spaces
  555.    \def\n{\vskip\baselineskip}%                 % \n gives a new line
  556.    \tt}                                         % switch to typewriter type
  557.      
  558. \def\uncatcode#1{\catcode`#1=\other}            % make a character "other"
  559.      
  560. {\obeyspaces\gdef {\ }}                        % space gives \ , not \space
  561.      
  562. %-----------------------------------*
  563. %       \TeXquoteon makes "|" active and a TeX quote. Anything enclosed
  564. % in | ... | is printed verbatim in \tt type; ^^M's are ignored.
  565. % \TeXquoteoff restores the normal |.
  566.      
  567. \def\TeXquoteon{\catcode`\|=\active}            % turn on "TeX quotes"
  568. \let\TeXquoteson=\TeXquoteon                    % synonym
  569. \def\TeXquoteoff{\catcode`\|=\other}            % turn off "TeX quotes"
  570. \let\TeXquotesoff=\TeXquoteoff                  % synonym
  571.      
  572. {\TeXquoteon\obeylines                          % active "|" calls \ttverbatim
  573.    \gdef|{\ifmmode\vert\else                    % | is \vert in math mode, but
  574.      \ttverbatim \spaceskip=\ttglue             % to use \tt type
  575.      \let^^M=\ %                                % and to ignore ^^M
  576.      \let|=\endgroup                            % next | turns it off
  577.      \fi}                                       % end of \gdef|
  578. }     
  579. %       \ttvert| gives a vertical bar in \tt type.  Use anywhere.
  580. \def\ttvert{\hbox{\tt\char`\|}}
  581.      
  582. %-----------------------------------*
  583. %       \begintt is taken without modification from The TeXbook, p. 421.
  584. % Like \TeXexample, it prints a TeX example in \tt type, but it puts the
  585. % example in a \vbox so that it cannot be split; it is ended by \endtt,
  586. % not |endtt:
  587. %
  588. %       \begintt
  589. %       <TeX stuff>
  590. %       \endtt
  591.      
  592. \outer\def\begintt{$$\let\par=\endgraf \ttverbatim \parskip=0pt
  593.    \catcode`\|=0 \rightskip=-5pc \ttfinish}
  594.      
  595. {\catcode`\|=0 |catcode`|\=\other       % | is temporary escape character
  596.    |obeylines                           % end of line is active
  597.    |gdef|ttfinish#1^^M#2\endtt{#1|vbox{#2}|endgroup$$}%
  598. }
  599.      
  600. %       \beginlines is also taken without modification from The TeXbook,
  601. % p. 421 and is also used for TeX examples. Each line of the example
  602. % must be enclosed in TeX quotes, | ... |. Spacing can be inserted using
  603. % \smallbreak and similar commands. The syntax is
  604. %       \TeXquoteon
  605. %       \beginlines
  606. %       | <TeX stuff> |
  607. %       ...
  608. %       \endlines
  609.      
  610. \def\beginlines{\par\begingroup\nobreak\medskip\parindent=0pt
  611.    \hrule\kern1pt\nobreak \obeylines \everypar{\strut}}
  612.      
  613. \def\endlines{\kern1pt\hrule\endgroup\medbreak\noindent}
  614.  
  615. %==================================================*
  616. %        \theorem, \lemma, \definition, \proof, etc..
  617. %
  618. % Quasi-SIAM format.  Theorem and Lemma have slanted typeface statements;
  619. % Definition does not.  Since Theorem and Lemma (and Corollary...) have
  620. % a similar structure, we define a general \beginproclaim and \endproclaim
  621. % (a'la PLAIN).
  622. %
  623. %       \beginproclaim{title}{countername}{font for text}{prefix}{tag}
  624. % does the general formatting, where the countername (excludes the \@
  625. % beginning the name) will be advanced.
  626.      
  627. \def\beginproclaim#1#2#3#4#5{\medbreak\vskip-\parskip   % space down
  628.    \global\XA\advance\csname #2\endcsname by \@ne       % advance counter
  629.    \edef\lab@l{\@chaptID\@sectID                        % get header plus
  630.       \number\csname #2\endcsname}%                     % counter number
  631.    \tag{#4#5}{\lab@l}%                                  % tag it
  632.    \noindent{\bf #1 \lab@l.\space}%                     % print number
  633.    \begingroup #3}                                      % begin group
  634.      
  635. \def\endproclaim{%
  636.    \par\endgroup\ifdim\lastskip<\medskipamount          % end group and
  637.    \removelastskip\penalty55\medskip\fi}                % fix spacing
  638.      
  639. %       \theorem{tag} defines a theorem. \Theorem{tag} refers to it in the
  640. % text as Theorem~number.
  641. \newcount\theoremnum           \theoremnum=\z@
  642. \def\theorem#1{\beginproclaim{Theorem}{theoremnum}{\sl}{Thm.}{#1}}
  643. \let\endtheorem=\endproclaim
  644. \def\Theorem#1{Theorem~\use{Thm.#1}}
  645.  
  646. %       The same for lemma:
  647. \newcount\lemmanum             \lemmanum=\z@
  648. \def\lemma#1{\beginproclaim{Lemma}{lemmanum}{\sl}{Lem.}{#1}}
  649. \let\endlemma=\endproclaim
  650. \def\Lemma#1{Lemma~\use{Lem.#1}}
  651.  
  652. %       The same for corollary:
  653. \newcount\corollarynum         \corollarynum=\z@
  654. \def\corollary#1{\beginproclaim{Corollary}{corollarynum}{\sl}{Cor.}{#1}}
  655. \let\endcorollary=\endproclaim
  656. \def\Corollary#1{Corollary~\use{Cor.#1}}
  657.      
  658. %       Definitions are little special; their text is not slanted.
  659. \newcount\definitionnum        \definitionnum=\z@     % Definition
  660. \def\definition#1{\beginproclaim{Definition}{definitionnum}{\rm}{Def.}{#1}}
  661. \let\enddefinition=\endproclaim
  662. \def\Definition#1{Definition~\use{Def.#1}}
  663.  
  664. %       Proofs are even more special.
  665. \def\proof{\medbreak\vskip-\parskip\noindent{\it Proof. }}
  666.      
  667. \def\blackslug{%                                % QED "black box"
  668.    \setbox0\hbox{(}%                            % ( gives size
  669.    \vrule width.5em height\ht0 depth\dp0}%      % use ) for size
  670. \def\QED{\blackslug}                            % to end proof
  671.      
  672. \def\endproof{\quad\blackslug\par\medskip}
  673.      
  674. % >>> EOF TXSenvmt.tex <<<
  675.